<template>
  <div class="first-contrainer">
    <div class="line"></div>
    <h3>
      搜索“<span style="font-size: 20px; color: red">{{
        this.$route.query.searchText
      }}</span
      >”，共{{ searchList.length }}条结果
    </h3>
    <div class="search-contrainer">
      <template v-for="item in searchList">
        <div class="item" :key="item.videoId">
          <img
            @click="look(item.videoId)"
            :src="item.videoCover"
            alt="图片加载失败"
          />
          <div class="produce">
            <span>{{ item.videoName }}</span>
          </div>
        </div>
      </template>
    </div>
    <el-empty description="没有匹配内容，换个电影名称试试" v-show="searchList.length==0"></el-empty>
  </div>
</template>

<script>
import { queryVideo } from "../../api/video";
export default {
  name: "First",
  data() {
    return {
      searchList: [],
      text: "",
    };
  },
  methods: {
    look(i) {
      this.$router.push({
        path: "/second",
        query: {
          v_id: i,
        },
      });
    },
  },
  mounted() {
    queryVideo(this.$route.query.searchText).then((res) => {
      if (res.data.code == 0) {
        this.searchList = res.data.page.list;
      } else {
        this.$message.error("出错咯！");
      }
    });
  },
  watch: {
    $route: {
      handler() {
        if (this.$route.query.searchText) {
          queryVideo(this.$route.query.searchText).then((res) => {
            if (res.data.code == 0) {
              this.searchList = res.data.page.list;
            } else {
              this.$message.error("出错咯！");
            }
          });
        }
      },
      deep: true,
    },
  },
};
</script>

<style lang="less" scoped>
.line {
  width: 100%;
  height: 1px;
  background-color: rgb(175, 168, 168);
}
.search-contrainer {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  justify-items: center;
  grid-gap: 15px 0;
  .item {
    border: 1px solid rgb(206, 201, 201);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 5px;
    border-radius: 5px;
    .produce {
      margin-top: 15px;
      font-size: 18px;
      font-weight: 600;
      letter-spacing: 0.5em;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-content: center;
    }
    img {
      border-radius: 3px;
      &:hover {
        transform: scale(1.05); //
        transition: all 0.6s; //
      }
    }
  }
}
</style>